#include <bits/stdc++.h>
// 2025/01/20
// tag:
// Author: Zhang Muen
using namespace std;

struct node
{
    unsigned int cnt;
    node *next[2];
    node() : cnt(-1)
    {
        next[0] = next[1] = nullptr;
    }
};

int n, m;
unsigned int input[500001];

unsigned int dfs(node *tree, unsigned int x)
{
    node *current = tree;
    for (int i = 31; i >= 0; i--)
    {
        bool v = !((x >> i) & 1);
        if (current->next[v])
            current = current->next[v];
        else
            current = current->next[!v];
    }
    return current->cnt;
}

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> input[i];

    node *tree = new node();

    for (int i = 1; i <= n; i++)
    {
        node *p = tree;
        unsigned int s = input[i];
        for (int k = 31; k >= 0; k--)
        {
            int bit = (s >> k) & 1;
            if (!p->next[bit])
                p->next[bit] = new node();
            p = p->next[bit];
        }
        p->cnt = s;
    }
    unsigned int p;
    for (int i = 1; i <= m; i++)
        cin >> p, cout << dfs(tree, p) << endl;
    return 0;
}